package com.feixiu.mapreduce.writablecomparable;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * 本地模式
 * 完全分布模式  需要把  项目打包成jar包，然后传到linux上运行
 */
public class FlowDriver {


    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1.获取job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);


        //2.关联jar包
        job.setJarByClass(FlowDriver.class);

        //3、关联mapper和reducer
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReducer.class);
        //4.设置mapper  输出的key 和value类型
        job.setMapOutputKeyClass( FlowBean.class);
        job.setMapOutputValueClass(Text.class);

        //5.设置最终输出的key和value 类型
        job.setOutputKeyClass(LongWritable.class);
        job.setOutputValueClass(Text.class);
        //6. 设置数据的输入路径和输出路径
        FileInputFormat.setInputPaths(job, new Path("D:\\Users\\hadoop\\output4"));
        FileOutputFormat.setOutputPath(job, new Path("D:\\Users\\hadoop\\output6"));
        //7.提交job  true  打印的日志信息更全
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
